var checkEmailResult = false;

/**
 * 重新验证注册信息
 */
function checkForm() {
	var passwd = getElementById("password");
	var passwd2 = getElementById("password2");
	// var email=getElementById("email");
	var idNumber = getElementById("idNumber");

	if (checkPasswd(passwd.value) && checkPasswd2(passwd2.value)
			&& checkRegistIds(idNumber.value)) {
		var temp = passwd.value;
		passwd.value = passwd2.value = hex_md5(temp);
		return true;
	} else {
		return false;
	}
}

/**
 * 检查身份证号
 */
function checkRegistIds(ids) {
	return checkId(ids, 'idNumber_font');
}

/**
 * 检查密码
 * 
 * @param passwd
 */
function checkPasswd(passwd) {

	var password_font = getElementById("password_font");
	if (passwd == undefined || passwd == "") {
		password_font.innerHTML = "密码不能为空";
	} else if (passwd.length < 6 || passwd.length > 18) {
		password_font.innerHTML = "密码长度应介于6-18";
	} else {
		password_font.innerHTML = "正确";
		return true;
	}

	return false;
}
/**
 * 密码确认
 */
function checkPasswd2(passwd2) {
	var passwd = getElementById("password");
	var password2_font = getElementById("password2_font");

	if (passwd.value != passwd2) {
		password2_font.innerHTML = "密码不匹配";
	} else if (passwd.value == passwd2 && passwd2.length >= 6
			&& passwd2.length <= 18) {
		password2_font.innerHTML = "正确";
		return true;
	}
	return false;
}

/**
 * 对注册的邮箱的格式和是否被注册进行检查
 * 
 * @param email
 */
function checkRegistEmail(email) {
	// 首先对邮箱的格式进行检查
	checkEmailResult = false;
	if (checkEmail(email, "email_font")) {
		isEmailExist(email);
	}
}

/**
 * 邮箱是否被注册
 */
function isEmailExist(email) {
	var email_font = getElementById("email_font");

	$.ajax({
		url : base_domain + '/base/isEmailExist.html',
		data : "email=" + email,
		type : 'post',
		dataType : 'json',
		contentType : "application/x-www-form-urlencoded;charset=utf-8",
		success : function(result) {
			if (result != "") {
				email_font.innerHTML = "该邮箱已被注册";
				checkEmailResult = false;
			} else {
				email_font.innerHTML = "恭喜，该邮箱可用";
				checkEmailResult = true;
			}
		},

		error : function() {
			alert("连接服务器出错");
		}
	});

}